package base;

import java.util.*;
import java.util.stream.Stream;

/**
 * @Author Klys
 * @Date 2023/3/23 0:03
 * @Description
 * @Version 1.0
 */
public class Demo02 {
    public static void main(String[] args) {

        //一维数组
        Integer[] array = {1, 2, 3, 4, 5};
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }

        //List集合：ArrayList
        ArrayList<Integer> arrayList = new ArrayList<Integer>(5);
        for (int i = 0; i < 5; i++) {
            arrayList.add(i);
        }
        System.out.println(arrayList);

        //Set集合：HashSet
        HashSet<Integer> hashSet = new HashSet<>(5);
        for (int i = 0; i < 5; i++) {
            hashSet.add(i);
        }
        System.out.println(hashSet);

        //map集合
        HashMap<Integer, Object> hashMap = new HashMap<Integer, Object>(5);
        for (int i = 0; i < 5; i++) {
            hashMap.put(i, i);
        }
        System.out.println(hashMap);

        //Queue队列:ArrayDeque
        Queue<Integer> queue = new ArrayDeque<Integer>();
        for (int i = 0; i < 5; i++) {
            queue.add(i);
        }
        System.out.println(queue);

        //链表linkedList
        LinkedList<Integer> linkedList = new LinkedList<>();
        for (int i = 0; i < 5; i++) {
            linkedList.add(i);
        }
        System.out.println(linkedList);

        //stream流处理：去大于3的值
        Stream<Integer> stream = arrayList.stream();
        stream.filter(value -> value > 3)
                .forEach((value) -> {
                    System.out.println(value);
                });

        //调用阶乘计算
        int value = 0;
        try {
            value = Demo02.Method(-1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(value);
    }

    //递归计算阶乘
    public static int Method(int value) throws Exception {
        if (value < 0) {
            throw new Exception("请输入正整数！");
        }
        if (value == 1) return 1;
        return Method(value - 1) * value;
    }
}
